<?php
class SupplierController extends AppController
{
	var $name = 'Supplier';
	var $helpers = array('Text');

	function index()
	{
//		$this->set('items', $this->Item->find('all'));
		$this->set('title_for_layout','悦淘会 - 每天都有优惠');
		$this->set('items', $this->paginate('Item'));
	}

	function view($id = null)
	{
		$this->Item->id = $id;
		$item = $this->Item->read();
		$this->set('title_for_layout',$item['Item']['title'] . ' - 悦淘会 - 每天都有优惠');
		$this->set('item', $item);
	}

	function add()
	{
		if(!empty($this->data))
		{
			if ($this->Item->save($this->data))
			{
				$this->redirect(array('controller' => 'item', 'action' => 'view', $this->Item->id));
			}
		}
	}

	function edit($id = null)
	{
		$this->Item->id = $id;
		if (empty($this->data))
		{
			$this->data = $this->Item->read();
		}
		else
		{
			if ($this->Item->save($this->data))
			{
				$this->Session->setFlash('updated');
				$this->redirect(array('controller' => 'item', 'action' => 'view', $this->Item->id));
			}
		}
	}

	function recommended()
	{
		$options = array(
			'conditions' => array(
				'Item.recommended' => 1, 
				'Item.end_time >' => time()
			),
			'order' => 'Item.created desc',
			'limit' => 3
		);
		return $this->Item->find('all', $options);
	}

	function latest()
	{
		$options = array(
			'conditions' => array(
				'Item.end_time >' => time(),
				'Item.recommended' => 0,
				'Item.city' => '北京'
			),
			'order' => 'Item.created desc',
			'limit' => '15'
		);
		return $this->Item->find('all', $options);
	}
}
?>
